home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Frameworks / GameShell / Sourcery / GameShellMonitor.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-03  |  3.7 KB  |  136 lines  |  [TEXT/CWIE]

  1. #include <Palettes.h>
  2.  
  3. #include "GameShellMonitor.h"
  4. #include "assert_mac.h"
  5.  
  6. enum {
  7.     /* Who's gonna have 10 monitors connect at once? This
  8.        should be a safe limit. */
  9.     kMaxMonitorsChecked = 10
  10. };
  11.  
  12. /*
  13.     Note: This routine is slightly buggy. I haven't had time to fix
  14.     this yet... It works OK for single-monitor systems, and is
  15.     slightly off with multiple-monitor systems.
  16. */
  17. short GameShellChooseMonitor(
  18.     GDHandle *monitor,
  19.     unsigned short preferredDepth,
  20.     unsigned short minDepth,
  21.     unsigned short minWidth,
  22.     unsigned short minHeight)
  23. /*
  24.     This routine, given the parameters, will select the "best fit"
  25.     monitor available. First it will look for the monitor that
  26.     matches the minimum dimensions. It then looks for the those
  27.     with the preferred depth first, and if none are available,
  28.     select those with the minimum available depth.
  29.     
  30.     The routine makes 2 passes. The first pass will query the
  31.     *current* depth of all monitors. If none are found (either
  32.     preferred or minimum) the second pass will query the
  33.     monitors if they're *able* to support the preferred and
  34.     minimum depths. If so, the routine will change the depth.
  35.     
  36.     If a monitor is found, the original depth of the monitor
  37.     will be returned. You can check this value against the
  38.     monitor's current depth to see if the routine was forced
  39.     to change the depth of the monitor.
  40.  
  41.     If no monitors are found, monitor will be set to NULL and
  42.     the routine will return 0.
  43. */
  44. {
  45.     Rect monitorRect;
  46.     GDHandle monitorList[kMaxMonitorsChecked];
  47.     GDHandle curMonitor;
  48.     short numMonitors;
  49.     short origDepth;
  50.     long i;
  51.     
  52.     // First make a list of all monitors that fit minimum dim
  53.     numMonitors = 0;
  54.     curMonitor = GetDeviceList();
  55.  
  56.     while (curMonitor != NULL) {
  57.         monitorRect = (**curMonitor).gdRect;
  58.  
  59.         if ( ((monitorRect.right - monitorRect.left) >= minWidth)
  60.           && ((monitorRect.bottom - monitorRect.top) >= minHeight) ) {
  61.             monitorList[numMonitors++] = curMonitor;
  62.         }
  63.         
  64.         curMonitor = GetNextDevice(curMonitor);
  65.     }
  66.     
  67.     // Found no monitors with the requested dimensions
  68.     if (numMonitors == 0) {
  69.         *monitor = NULL;
  70.         return(0);
  71.     }
  72.     
  73.     // Look for any with the preferred depth
  74.     for (i = 0; i < numMonitors; i++) {
  75.         // Get current depth
  76.         origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
  77.  
  78.         if (origDepth >= preferredDepth) {
  79.             if (origDepth != preferredDepth)
  80.                 SetDepth(monitorList[i], preferredDepth, 1 << gdDevType, 1);
  81.             *monitor = monitorList[i];
  82.             return(origDepth);
  83.         }
  84.     }
  85.     
  86.     // If we get to here, means didn't find the preferred.
  87.     // Now look for minimum
  88.     for (i = 0; i < numMonitors; i++) {
  89.         origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
  90.         
  91.         if (origDepth >= minDepth) {
  92.             if (origDepth != minDepth) 
  93.                 SetDepth(monitorList[i], minDepth, 1 << gdDevType, 1);
  94.             *monitor = monitorList[i];
  95.             return(origDepth);
  96.         }
  97.     }
  98.     
  99.     // Are any monitors available that can be at least
  100.     // *set* to the preferred depth?
  101.     for (i = 0; i < numMonitors; i++) {
  102.         origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
  103.         
  104.         if (HasDepth(monitorList[i], preferredDepth, 1 << gdDevType, 1)) {
  105.             SetDepth(monitorList[i], preferredDepth, 1 << gdDevType, 1);
  106.             *monitor = monitorList[i];
  107.             return(origDepth);
  108.         }
  109.     }
  110.     
  111.     // Are any monitors that can be set to the minimum depth?
  112.     for (i =0; i < numMonitors; i++) {
  113.         origDepth = (**(**monitorList[i]).gdPMap).pixelSize;
  114.  
  115.         if (HasDepth(monitorList[i], minDepth, 1 << gdDevType, 1)) {
  116.             SetDepth(monitorList[i], minDepth, 1 << gdDevType, 1);
  117.             *monitor = monitorList[i];
  118.             return(origDepth);
  119.         }
  120.     }
  121.     
  122.     *monitor = NULL;
  123.     return(0);
  124. } // END GameShellSelectMonitor
  125.  
  126.  
  127. short GameShellUserSelectMonitor(
  128.     GDHandle *monitor,
  129.     unsigned short preferredDepth,
  130.     unsigned short minDepth,
  131.     unsigned short minWidth,
  132.     unsigned short minHeight)
  133. {
  134.     // Sorry, not currently implemented.
  135.     return(0);
  136. } // END GameShellUserSelectMonitor